package org.wiztools.commons.feed;

import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import org.apache.log4j.Logger;

/**
 *
 * @author subhash
 */
public class RomeFeedExecuter extends AbstractFeedExecuter {

    private static final Logger LOG = Logger.getLogger(RomeFeedExecuter.class);

    public Feed getFeed(URL url) throws FeedException, IOException {
        Feed f = null;
        final SyndFeedInput input = new SyndFeedInput();
        try {
            final SyndFeed romeFeed = input.build(
                    new XmlReader(HttpUtil.getConnectionStream(url, options)));
            f = new Feed();
            f.setTitle(romeFeed.getTitle());
            String link = romeFeed.getLink();
            if (link != null) {
                f.setUrl(new URL(link));
            }

            List<SyndEntry> romeEntryList = romeFeed.getEntries();

            List<FeedEntry> l = RomeUtil.getEntries(romeEntryList);

            f.setEntries(l);

        } catch (com.sun.syndication.io.FeedException ex) {
            throw new FeedException(ex);
        }
        return f;
    }
}
